package com.qf.commerce.controller;

import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.ChannelDto;
import com.qf.commerce.common.dto.MessageDto;
import com.qf.commerce.common.dto.SampleDto;
import com.qf.commerce.common.vo.ChannelVo;
import com.qf.commerce.common.vo.MessageVo;
import com.qf.commerce.common.vo.SampleVo;
import com.qf.commerce.resp.ResponseResult;
import com.qf.commerce.service.ChannelService;
import com.qf.commerce.service.MessageService;
import com.qf.commerce.service.SampleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/contents")
@Api(tags="内容管理Api接口文档")
public class ContentsController {

    @Resource
    ChannelService channelService;
    @Resource
    MessageService messageService;

    @Resource
    SampleService sampleService;
    @GetMapping("/message/list")
    @ApiOperation("展示资讯列表")
    public ResponseResult<PageInfo<MessageVo>> queryMessageList(@RequestParam ("currentPage") Integer currentPage){
        try {
            return ResponseResult.success(messageService.selectMessageList(currentPage));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @PostMapping("/message/search/")
    @ApiOperation("展示条件查询的资讯列表")
    public ResponseResult<PageInfo<MessageVo>> queryMessageListByBeans(@RequestBody MessageDto messageDto,@RequestParam("currentPage")Integer currentPage){
        try {
            return ResponseResult.success(messageService.selectMessageByBeans(messageDto,currentPage));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @DeleteMapping("/message/delete")
    @ApiOperation("根据资讯ID假删除资讯")
    @ApiImplicitParam(name = "messageId",value="资讯ID",required = true,paramType = "query")
    public ResponseResult<Integer> deleteMessageById(@RequestParam("messageId") Long messageId){
        try {
            return ResponseResult.success(messageService.deleteMessage(messageId));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @DeleteMapping("/message/deletes")
    @ApiOperation("根据资讯ID集合批量假删除资讯")
    @ApiImplicitParam(name = "messageIds",value = "资讯ID集合",required = true,paramType = "query")
    public ResponseResult<Integer> deleteMessageByIds(@RequestParam("messageIds") List<Long> messageIds){
        try {
            return ResponseResult.success(messageService.deleteMessages(messageIds));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }
    @PostMapping("/message/add")
    @ApiOperation("根据资讯请求参数对象添加资讯")
    public ResponseResult<Integer> addMessage(@RequestBody MessageDto messageDto){
        try {
            return ResponseResult.success(messageService.addMessage(messageDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }
    @PutMapping("/message/update")
    @ApiOperation("根据资讯请求参数对象修改资讯")
    public ResponseResult<Integer> modifyMessageById(@RequestBody MessageDto messageDto){
        try {
            return ResponseResult.success(messageService.modifyMessage(messageDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }
    @PutMapping("/message/switch")
    @ApiOperation("根据资讯请求参数对象修改资讯推荐状态")
    public ResponseResult<Integer> switchMessageStatus(@RequestBody MessageDto messageDto){
        try {
            return ResponseResult.success(messageService.switchMessageStatus(messageDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }
    @PostMapping("/channel/add")
    @ApiOperation("根据频道请求参数对象添加频道")
    public ResponseResult<Integer> addChannel(@RequestBody ChannelDto channelDto){
        try {
            return ResponseResult.success(channelService.addChannel(channelDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @DeleteMapping("/channel/delete")
    @ApiOperation("根据频道ID假删除频道")
    @ApiImplicitParam(name = "channelId",value = "频道ID",required = true,paramType = "query")
    public ResponseResult<Integer> deleteChannelById(@RequestParam("channelId") Long channelId){
        try{
            return ResponseResult.success(channelService.deleteChannelById(channelId));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @DeleteMapping("/channel/deletes")
    @ApiOperation("根据频道ID集合批量假删除频道")
    @ApiImplicitParam(name = "channelIds",value = "频道ID集合",required = true,paramType = "query")
    public ResponseResult<Integer> deleteChannelByIds(@RequestParam("channelIds") List<Long> channelIds){
        try {
            return ResponseResult.success(channelService.deleteChannelByIds(channelIds));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @PutMapping("/channel/update")
    @ApiOperation("根据频道请求参数对象修改频道")
    public ResponseResult<Integer> modifyChannelById(@RequestBody ChannelDto channelDto){
        try {
            return ResponseResult.success(channelService.modifyChannelById(channelDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @GetMapping("/channel/list")
    @ApiOperation("展示频道列表")
    public ResponseResult<PageInfo<ChannelVo>> queryChannelList(@RequestParam("currentPage")Integer currentPage){
        try {
            return ResponseResult.success(channelService.queryChannelList(currentPage));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @PostMapping("/channel/search/")
    @ApiOperation("展示条件查询的频道列表")
    public ResponseResult<PageInfo<ChannelVo>> queryChannelListByBeans(@RequestBody ChannelDto channelDto,@RequestParam("currentPage")Integer currentPage){
        try {
            return ResponseResult.success(channelService.queryChannelByBeans(channelDto,currentPage));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }


    @PostMapping("/sample/add")
    @ApiOperation("根据模型请求参数对象添加模型")
    public ResponseResult<Integer> addSample(@RequestBody SampleDto sampleDto){
        try {
            return ResponseResult.success(sampleService.addSample(sampleDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @PutMapping("/sample/update")
    @ApiOperation("根据模型请求参数对象修改模型")
    public ResponseResult<Integer> updateSample(@RequestBody SampleDto sampleDto){
        try {
            return ResponseResult.success(sampleService.modifySampleById(sampleDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @DeleteMapping("/sample/delete")
    @ApiOperation("根据模型ID假删除模型")
    @ApiImplicitParam(name = "sampleId",value = "模型ID",required = true,paramType = "query")
    public ResponseResult<Integer> deleteSample(@RequestParam("sampleId") Long sampleId){
        try {
            return ResponseResult.success(sampleService.deleteSampleById(sampleId));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @DeleteMapping("/sample/deletes")
    @ApiOperation("根据模型ID集合批量假删除模型")
    @ApiImplicitParam(name = "sampleIds",value = "模型ID集合",required = true,paramType = "query")
    public ResponseResult<Integer> deleteSamples(@RequestParam("sampleIds") List<Long> sampleIds){
        try {
            return ResponseResult.success(sampleService.deleteSampleByIds(sampleIds));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @GetMapping("/sample/list")
    @ApiOperation("展示模型列表")
    public ResponseResult<PageInfo<SampleVo>> querySampleList(@RequestParam("currentPage") Integer currentPage){
        try {
            return ResponseResult.success(sampleService.querySampleList(currentPage));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @GetMapping("/sample/search/")
    @ApiOperation("根据模型名展示模糊查询的模型列表")
    @ApiImplicitParam(name = "modelName",value = "模型名称",required = true,paramType = "query")
    public ResponseResult<PageInfo<SampleVo>> querySampleByName(@RequestParam("modelName") String modelName,@RequestParam("currentPage") Integer currentPage){
        try {
            return ResponseResult.success(sampleService.querySampleByName(modelName,currentPage));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }
}
